using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2024-10-21
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 批次号工位绑定表
    /// </summary>
    [Verify]
    [Route("business/BatchBinding")]
    [ApiExplorerSettings(GroupName = "business")]
    public class BatchBindingController : BaseController
    {
        /// <summary>
        /// 批次号工位绑定表接口
        /// </summary>
        private readonly IBatchBindingService _BatchBindingService;

        public BatchBindingController(IBatchBindingService BatchBindingService)
        {
            _BatchBindingService = BatchBindingService;
        }

        /// <summary>
        /// 查询批次号工位绑定表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "batchbinding:list")]
        public IActionResult QueryBatchBinding([FromQuery] BatchBindingQueryDto parm)
        {
            var response = _BatchBindingService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询批次号工位绑定表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "batchbinding:query")]
        public IActionResult GetBatchBinding(int Id)
        {
            var response = _BatchBindingService.GetInfo(Id);

            var info = response.Adapt<BatchBindingDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加批次号工位绑定表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "batchbinding:add")]
        [Log(Title = "批次号工位绑定表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddBatchBinding([FromBody] BatchBindingDto parm)
        {
            var modal = parm.Adapt<BatchBinding>().ToCreate(HttpContext);

            var response = _BatchBindingService.AddBatchBinding(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新批次号工位绑定表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "batchbinding:edit")]
        [Log(Title = "批次号工位绑定表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateBatchBinding([FromBody] BatchBindingDto parm)
        {
            var modal = parm.Adapt<BatchBinding>().ToUpdate(HttpContext);
            var response = _BatchBindingService.UpdateBatchBinding(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除批次号工位绑定表
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "batchbinding:delete")]
        [Log(Title = "批次号工位绑定表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteBatchBinding([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_BatchBindingService.Delete(idArr));
        }
    }
}